$(document).ready(function() {
	
	// 点击登录
	$("#btnLogin").click(function () {
		var userName = $("#userName").val();
		if (userName == null || userName.trim().length < 1) {
			alert("请输入用户名");
			return;
		}
		var password = $("#password").val();
		if (password == null || password.trim().length < 1) {
			alert("请输入密码");
			return;
		}
		var roleName = $("#roleName").val();
		if (roleName == null || roleName.trim().length < 1) {
			alert("请选择角色");
			return;
		}
		
		// 数据提交
//		var data = {userName:userName, password:password, roleName:roleName};
		var data = {};
		data.userName = userName, data.password = password, data.roleName = roleName;
		$.post(ctx + "user/login", data, function(res) {
			console.log(res);
			if (res.resultCode == 1) { // 判断是否成功
				
				// 获取登录信息存入cookie
				var userLoginIdentity = res.result;
				var userName = userLoginIdentity.userName;
				var realName = userLoginIdentity.realName;
				var roleName = userLoginIdentity.roleName;
				var userIdString = userLoginIdentity.userIdString;
				$.cookie('userName', userName);
				$.cookie('realName', realName);
				$.cookie('roleName', roleName);
				$.cookie('userIdString', userIdString);
				
				// 跳转
				window.location.href = ctx + "main";
				
			} else {
				alert(res.message);
			}
		});
		
		
	});
	
});
